package com.handsure.boot.controller;

import com.handsure.boot.redis.RedisBaseOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Arvin.Cao
 * @ClassName RedisTestController
 * @Description redis测试
 * @date 16/1/14
 */
@Controller
public class RedisTestController {
    @Autowired
    RedisBaseOperation<String> redisBaseOperation;

    /**
     * 保存redis参数
     *
     * @return
     */
    @RequestMapping(value = "/redis", method = RequestMethod.PUT)
    @ResponseBody
    public Object saveObj(@RequestParam(name = "key") String key, @RequestParam(name = "value") String value) {
        redisBaseOperation.saveOrUpdate(key, value);
        return "111";
    }


    /**
     * 获取redis参数
     *
     * @return
     */
    @RequestMapping(value = "/redis", method = RequestMethod.GET)
    @ResponseBody
    public Object getObj(@RequestParam(name = "key") String key) {
        String value = (String)redisBaseOperation.get(key);
        return value;
    }
}
